//@author A0081189X
package net.mysoc.w111j.service.actions;

import net.mysoc.w111j.model.PaymentType;
import net.mysoc.w111j.model.User;

/**
 * An {@code Action} to undo the adding of a {@code PaymentType}.
 */
public class AddPaymentTypeAction implements Action {
    private final User user;
    private final int newPaymentTypeId;
    private String status;

    public AddPaymentTypeAction(User user, PaymentType newPaymentType) {
        this.user = user;
        this.newPaymentTypeId = newPaymentType.getId();
        setStatus(newPaymentType);
    }

    @Override
    public void undo() {
        // The category should have no expenses prior to undoing,
        // therefore it is safe to just delete the category.
        user.removePaymentType(newPaymentTypeId);
    }

    private void setStatus(PaymentType paymentType) {
        status = "New payment type added: " + paymentType.getName() + ".";
    }

    @Override
    public String getStatus() {
        return status;
    }
}
